package com.linkhouse.common.data;


import com.linkhouse.common.em.ResultEnum;

public class Result<T> {

    private Integer code;
    private String message;
    private T data;


    public static Result OK(){
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getStatus()); //自定义成功返回码
        result.setMessage(ResultEnum.SUCCESS.getStatusInfo());
        return result;
    }


    public static Result ERROR(){
        Result result = new Result();
        result.setCode(ResultEnum.ERROR.getStatus()); //自定义成功返回码
        result.setMessage(ResultEnum.ERROR.getStatusInfo());
        return result;
    }

    public static Result RESPONSE(Integer code,String message){//用户不存在 密码错误
        Result result = new Result();
        result.setCode(code); //自定义成功返回码
        result.setMessage(message);
        return result;
    }


    public static Result R(ResultEnum resultEnum){
        Result r = new Result();
        r.setCode(resultEnum.getStatus());
        r.setMessage(resultEnum.getStatusInfo());

        return r;
    }

    public static Result Fallback() {
        Result result = new Result();
        result.setCode(ResultEnum.FEIGN_FALLBACK.getStatus()); //自定义成功返回码
        result.setMessage(ResultEnum.FEIGN_FALLBACK.getStatusInfo());
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

}
